package com.demo2do.boyle.common.entity.aduser;


import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

import com.alibaba.fastjson.annotation.JSONField;

/**
 * 广告主账户余额表
 * 
 * @author mohanlan
 */
@Entity
@Table( name = "aduser_balance" )
public class AduserBalance {
	
	@Id
	@GeneratedValue(generator = "gen")
	@GenericGenerator(name = "gen", strategy = "foreign", parameters = @Parameter( name = "property", value = "aduser"))
	private Integer id; 
	
	@OneToOne(fetch = FetchType.LAZY)
	@PrimaryKeyJoinColumn
	@JSONField(serialize = false)
	private Aduser aduser;
	
	/** 账户余额 */
	private int balance;
	
	/** 消费总计 */
	private int consumeTotal;
	
	/** 充值总计 */
	private int depositTotal;
	
	/** 质检退款总计 */
	private int refundTotal;
	
	/**
	 * default constructor;
	 */
	public AduserBalance() {
		this.balance = 0;
		this.consumeTotal = 0;
		this.depositTotal = 0;
		this.refundTotal = 0;
	}
	
	/**
	 * 
	 * @param aduser
	 */
	public AduserBalance(Aduser aduser) {
		this.balance = 0;
		this.consumeTotal = 0;
		this.depositTotal = 0;
		this.refundTotal = 0;
		this.aduser = aduser;
	}
	
	/**
	 * 
	 * @param deposit
	 * @return
	 */
	public AduserBalance deposit(int deposit) {
		this.balance += deposit;
		this.depositTotal += deposit;
		return this;
	}

	/**
	 * 
	 * @param balance
	 * @return
	 */
	public AduserBalance refund(int balance) {
		this.balance += balance;
		this.refundTotal += balance;
		return this;
	}
	
	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @return the aduser
	 */
	public Aduser getAduser() {
		return aduser;
	}

	/**
	 * @return the balance
	 */
	public int getBalance() {
		return balance;
	}

	/**
	 * @return the consumeTotal
	 */
	public int getConsumeTotal() {
		return consumeTotal;
	}

	/**
	 * @return the depositTotal
	 */
	public int getDepositTotal() {
		return depositTotal;
	}

	/**
	 * @return the refundTotal
	 */
	public int getRefundTotal() {
		return refundTotal;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @param aduser the aduser to set
	 */
	public void setAduser(Aduser aduser) {
		this.aduser = aduser;
	}

	/**
	 * @param balance the balance to set
	 */
	public void setBalance(int balance) {
		this.balance = balance;
	}

	/**
	 * @param consumeTotal the consumeTotal to set
	 */
	public void setConsumeTotal(int consumeTotal) {
		this.consumeTotal = consumeTotal;
	}

	/**
	 * @param depositTotal the depositTotal to set
	 */
	public void setDepositTotal(int depositTotal) {
		this.depositTotal = depositTotal;
	}

	/**
	 * @param refundTotal the refundTotal to set
	 */
	public void setRefundTotal(int refundTotal) {
		this.refundTotal = refundTotal;
	}

}
